#include <cstdio>
#include <stack>
#include <cstring>
using namespace std;

int N;
stack<int> ans;
bool book[2005];

bool DFS(int n, int a) {
    if (a == 1) {
        ans.push(a);
        return true;
    }
    if (ans.size() < 99) {
        for (int i=0; i<=9; i++) {
            if (i == 0 && a == 0) continue;
            int t = (n*i+a)%10;
            if (t == 0 || t == 1) {
                //if (n*i+a == prev) continue;
                if (book[n*i+a]) continue;
                ans.push(t);
                //printf("%d %d %d\n", i, n*i+a, a);
                if (n*i+a > 0) {
                    book[n*i+a] = true;
                    if (DFS(n, (n*i+a)/10)) return true;
                    book[n*i+a] = false;
                }
                ans.pop();
            }
        }
    }
    return false;
}


int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    while (scanf("%d", &N) == 1 && N) {
        ans = stack<int>();
        memset(book, 0, sizeof(book));
        if (N==1) {
            printf("1");
        } else {
            if (DFS(N, 0)) {
                while (!ans.empty()) {
                    int t = ans.top(); ans.pop();
                    printf("%d", t);
                }
            }
        }
        printf("\n");
    }
    return 0;
}
